package service;

import dao.UsersDaoImpl;
import dao.UsersInterface;
import entity.Users;
import util.Oprea;

import java.io.File;
import java.util.List;

public class UserServiceImpl implements UserService {
    File file = new File("users.txt");
    UsersInterface usersInterface;
    public UserServiceImpl() {
        usersInterface = new UsersDaoImpl();
    }

    @Override
    public boolean addUser(Users users) {
        return usersInterface.addUser(users);

    }

    @Override
    public boolean checkLogin(String userName, String pwd) {
        UsersDaoImpl usersDao = new UsersDaoImpl();
        List<Users> user = Oprea.unseriaUser(file);
        if (user != null) {
            for (Users users : user) {
                if (users.getName().equals(userName) && users.getPaswward().equals(pwd)) {
                    return true;
                }
            }
        }
        return false;
    }
}
